package design.mode.effective_java.chapter3.item10;

/**
 * @author ZhongMingde on 2021/8/11
 */

public class ColorPoint extends Point {

    private final Color color;

    public ColorPoint(int x, int y, Color color) {
        super(x, y);
        this.color = color;
    }

    @Override
    public boolean equals(Object o) {
        /*
        if (!(o instanceof ColorPoint)){
            return false;
        }
        return super.equals(o) && ((ColorPoint) o).color == color;
        结果
        System.out.println(p.equals(cp)); // true
        System.out.println(cp.equals(p)); // false

        */

        /*if (!(o instanceof Point)) {
            return false;
        }
        if (!(o instanceof ColorPoint)) {
            return o.equals(this);
        }
        return super.equals(o) && ((ColorPoint) o).color == color;
        ColorPoint p1 = new ColorPoint(1, 2, new Color());
        Point p2 = new Point(1, 2);
        ColorPoint p3 = new ColorPoint(1, 2, new Color());
        System.out.println(p1.equals(p2)); // true
        System.out.println(p2.equals(p3)); // true
        System.out.println(p1.equals(p3)); // false
        */

        return false;
    }


    public static void main(String[] args) {
        ColorPoint p1 = new ColorPoint(1, 2, new Color());
        Point p2 = new Point(1, 2);
        ColorPoint p3 = new ColorPoint(1, 2, new Color());
        System.out.println(p1.equals(p2)); // true
        System.out.println(p2.equals(p3)); // true
        System.out.println(p1.equals(p3)); // false
    }
}
